package com.tuanzi.loan.web.bean.collaborate;

import com.tuanzi.loan.business.entity.common.CommProductChannel;
import com.tuanzi.loan.business.service.collaborate.CollaborateChannelRatioService;
import com.tuanzi.loan.business.service.common.CommProductChannelService;
import com.tuanzi.loan.vo.request.statistics.login.StatMarketLoginRequest;
import com.tuanzi.loan.vo.response.collaborate.StatCollaborateMarketLoginResponse;
import com.tuanzi.loan.web.configuration.JSFListingBean;
import com.tuanzi.loan.web.lazy.collaborate.CollaborateMarketListLazyDataModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
import java.util.List;
import java.util.Set;

/**
 * User: liangZongXi
 * Create time: 10:42 2019/5/9
 * Description:
 */
@Data
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class CollaborateMarketListBean extends JSFListingBean<StatMarketLoginRequest, StatCollaborateMarketLoginResponse> {
    private static final long serialVersionUID = 856876679643489151L;

    @Autowired
    private CommProductChannelService commProductChannelService;
    @Autowired
    private CollaborateChannelRatioService collaborateChannelRatioService;

    private List<CommProductChannel> currentUserChannelList;
    private Set<Integer> showTypeSet;

    @PostConstruct
    public void init(){
        $ = new StatMarketLoginRequest();
        lazyDataModel = new CollaborateMarketListLazyDataModel($);
        initChannels();
        initShowSet();
    }

    private void initChannels(){
        if(null == currentUserChannelList || currentUserChannelList.size() == 0){
            currentUserChannelList = commProductChannelService.findCurrentUserChannels();
        }
    }

    private void initShowSet(){
        if(null == showTypeSet || showTypeSet.size() == 0){
            showTypeSet = collaborateChannelRatioService.findCurrentUserMarketShow(currentUserChannelList);
        }
    }

    public void onRest(){
        init();
    }


    public Boolean isShow(Integer colNum){
        if(null != colNum){
            if(showTypeSet.contains(colNum)){
                return true;
            }
        }

        return false;
    }

}
